
package org.javaqq.face.main.lookandfeel;

import java.awt.*;

import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;

import org.javaqq.face.resources.Info;
import org.javaqq.face.resources.ResourcesManager;
import org.javaqq.face.util.AntialiasingManager;
import org.javaqq.face.util.ImageUtils;


public class JavaQQChatSelectorMenuUI
    extends BasicMenuUI
{
    private final Image menuBgImage
        = ImageUtils.getImage(ResourcesManager.getResourcesManagerFactory().getImageValue(Info.MSG_TOOLBAR_BUTTON_BG));

    public static ComponentUI createUI(JComponent x)
    {
        return new JavaQQChatSelectorMenuUI();
    }

    /**
     * Draws the background of the menu item.
     * 
     * @param g the paint graphics
     * @param menuItem menu item to be painted
     * @param bgColor selection background color
     * @since 1.4
     */
    protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
    {
        super.paintBackground(g, menuItem, bgColor);

        boolean isToolBarExtended =
            new Boolean(ResourcesManager.getResourcesManagerFactory().getDefaultsValue(Info.JAVAQQ_IS_TOOLBAR_EXTENDED)).booleanValue();

        if (!isToolBarExtended)
        {
            g = g.create();
            try
            {
                AntialiasingManager.activateAntialiasing(g);

                int menuWidth = menuItem.getWidth();
                int menuHeight = menuItem.getHeight();

                g.drawImage(menuBgImage, 0, 0, menuWidth, menuHeight, null);
            }
            finally
            {
                g.dispose();
            }
        }
    }
}
